<div class="jobs index">
<h2><?php __('Jobs');?></h2>
<!-- Table Navigation -->
<div class="tablenav">
    <div class="batchactions"></div>
    <?php echo $this->element('pager'); ?>
</div>
<!-- Table Content Area -->
<table id="table_jobs" class="table fixed">
    <thead title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th width="4%" class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox"/></th>
            <th width="27%"><?php echo $paginator->sort('title');?></th>
            <th width="25%"><?php echo $paginator->sort('company_id');?></th>
            <th width="12%"><?php echo $paginator->sort('workplace');?></th>
            <th width="12%"><?php echo $paginator->sort('students_job_count');?></th>
            <th width="20%"><?php echo $paginator->sort('created');?></th>
        </tr>
    </thead>
    <tfoot title="<?php __('Click a column to sort data table'); ?>">
        <tr>
            <th class="checkbox" title="<?php __('Click to select/deselect all records'); ?>"><input type="checkbox" class="checkbox"/></th>
            <th><?php echo $paginator->sort('title');?></th>
            <th><?php echo $paginator->sort('company_id');?></th>
            <th><?php echo $paginator->sort('workplace');?></th>
            <th><?php echo $paginator->sort('students_job_count');?></th>
            <th><?php echo $paginator->sort('created');?></th>
        </tr>
    </tfoot>
    <tbody>
        <?php foreach ($jobs as $i=>$job):
            $class = $i++ % 2 == 0 ? ' class="altrow"' : ''; ?>
        <tr<?php echo $class;?>>
            <!-- Job.Checkbox -->
            <td class="checkbox"><input type="checkbox" class="checkbox"/></td>
            <!-- Job.title -->
            <td class="title">
                <p class="name">
                    <?php e($html->link($job['Job']['title'],
                        array('action'=>'view', $job['Job']['id']),
                        array('title'=>$job['Job']['title'], 'rev'=>'external')
                    )); ?>
                </p>
                <p class="modified">
                    <?php __('Modified on'); ?>&nbsp;
                    <?php echo $html->link($time->format($options['longDateFormat'], $job['Job']['modified']),
                        array('modified' => $time->format($options['queryDateFormat'], $job['Job']['modified'])),
                        array('title' => sprintf(__('View jobs modified on %s', true), $time->format($options['queryDateFormat'], $job['Job']['created'])))
                    ); ?><br />
                    <?php __('Modified by'); ?>&nbsp;
                    <?php echo $html->link($job['ModifiedUser']['username'],
                        array('modified_by' => $job['ModifiedUser']['username']),
                        array('title' => sprintf(__('View jobs modified by %s', true), $job['ModifiedUser']['username']))
                    ); ?>
                </p>
                <?php if($job['Job']['expired']){
                        $exp_display = 'none';
                        $unexp_display = 'inline';
                    }else{
                        $exp_display = 'inline';
                        $unexp_display = 'none';
                    }
                ?>
                <p class="actions">
                    <span class="expire" style="display: <?php e($exp_display); ?>">
                        <?php echo $html->link(__('make expired', true),
                            array('action'=>'switchOn', 'expired', $job['Job']['id']),
                            array('title' => __('mark this job as expired, students will not see them again', true))); ?>
                    </span>
                    <span class="unexpire" style="display: <?php e($unexp_display); ?>">
                        <?php echo $html->link(__('make valid', true),
                            array('action'=>'switchOff', 'expired', $job['Job']['id']),
                            array('title' => __('mark this job as valid, so students will apply for it', true))); ?>
                    </span>
                    <span class="view">
                        <?php echo $html->link(__('View', true),
                            array('action'=>'view', $job['Job']['id'])); ?>
                    </span>
                    <?php if($user['group'] != 'student'): ?>
                        <span class="edit">
                            <?php echo $html->link(__('Edit', true),
                                array('action'=>'edit', $job['Job']['id'])); ?>
                        </span>
                        <span class="delete">
                            <?php echo $html->link(__('Delete', true),
                                array('action'=>'delete', $job['Job']['id'])); ?>
                        </span>
                    <?php else: ?>
                        <span class="apply">
                            <?php e($html->link(__('Apply', true),
                                array('controller'=>'students_jobs', 'action' => 'add', $job['Job']['id']))); ?>
                        </span>
                    <?php endif; ?>
                </p>
            </td>
            <td class="company">
                <p class="name">
                    <?php e($html->link($job['Company']['name'],
                        array('company_id'=>$job['Company']['id']),
                        array('title'=>$job['Company']['name'])
                    )); ?>
                    <?php e($text->autoLinkUrls($job['Company']['website'],
                        array(
                            'title'=>__('Click to visit the official website of the company', true),
                            'class'=>'external')
                    )); ?>
                </p>
                <p class="email">
                    <?php echo $text->autoLinkEmails($job['Company']['email'],
                        array('title'=>sprintf(__('Send mail to: %s', true), $job['Company']['name']))); ?>
                </p>
            </td>
            <!-- Job.workplace -->
            <td class="workplace">
                <p class="workplace">
                <?php echo $html->link($job['Job']['workplace'],
                    array('workplace'=>$job['Job']['workplace']),
                    array('title' =>sprintf(__('View jobs that work in %s', true), $job['Job']['workplace']))); ?>
                </p>
            </td>
            <td class="students">
                <p class="counter">

                    <?php printf(__('%d application', true), $job['Job']['students_job_count']); ?>
                </p>
                <!-- Print view detail and export links for admins -->
                <?php if($user['group'] != 'student' && $job['Job']['students_job_count']>0): ?>
                <p class="detail">
                    <?php echo $html->link(__('view detail', true),
                        array('controller'=>'jobs', 'action'=>'student', 'job'=>$job['Job']['id'], 'export' =>false ),
    
                    array('title'=>__('view who have applied this job', true) )
                    ); ?>
                </p>
                <p class="export">
    
                <?php echo $html->link( __('export as csv', true),
                        array( 'controller'=>'jobs', 'action'=>'student', 'job'=>$job['Job']['id'], 'export' =>true ),
    
                    array( 'title'=>__('export student data that has applied for this job', true))
                    ); ?>
                </p>

                <?php endif; ?>
            </td>
            <!-- Job.created & Job.clicks -->
            <td class="created">
                <p class="created">
                    <?php __('Created on'); ?>
                    <?php echo $html->link($time->format($options['longDateFormat'], $job['Job']['created']),
                        array('created' => $time->format($options['queryDateFormat'], $job['Job']['created'])),
                        array('title' => sprintf(__('View jobs added on %s', true), $time->format($options['queryDateFormat'], $job['Job']['created'])))
                    ); ?><br />
                    <?php __('Created By'); ?>&nbsp;
                    <?php echo $html->link($job['CreatedUser']['username'],
                        array('created_by' => $job['CreatedUser']['username']),
                        array('title' => sprintf(__('View companies created by %s', true), $job['CreatedUser']['username']))
                    ); ?>
                </p>
                <p class="clicks">
                    <?php printf(__('Clicks: %d', true), $job['Job']['clicks']); ?>
                </p>
            </td>
        </tr>
        <?php endforeach; ?>
    <tbody>
</table>
</div>

<?php //debug($jobs); ?>

<script type="text/javascript">
jQuery(function(){
    /* Apply for the job through ajax */
    $('table#table_jobs p.actions a[href*=delete]').click($.sme.cbk.ajaxDelete);
    $('table#table_jobs p.actions a[href*=students_jobs]').click($.sme.cbk.ajaxApply);
    $('table#table_jobs p.actions a[href*=switchOn]').click($.sme.cbk.ajaxSwitchOn);
    $('table#table_jobs p.actions a[href*=switchOff]').click($.sme.cbk.ajaxSwitchOff);
    /* Show hide action links */
    $('tbody tr').hover($.sme.cbk.showActions, $.sme.cbk.hideActions);
});
</script>